<template>
	<view class="delay-list accident-list pb-60">
		<view>
			<view class="search">
				<view style="background-color: #fff;margin: 0 10px;border-radius: 5px;height: 42px;" class="uni-flex">
					<view style="-webkit-flex: 1;flex: 1;" class="uni-flex">
						<view class="date-p"><uni-datetime-picker type="date" v-model="createdAt" :border="false"
								placeholder="登记日期"  @change="changeDate" />
						</view>
					</view>
					<!-- <view class="search-btn"><uni-icons type="search" color="#fff" size="20" /></view> -->
				</view>
			</view>
			<view class="uni-mlr-10">
				<z-paging ref="paging" v-model="dataList" @query="queryList">
					<!-- 设置自己的emptyView组件，非必须。空数据时会自动展示空数据组件，不需要自己处理 -->
					<view slot="empty" class="empty text-center text-sm"><text>暂时没有数据~</text>
					</view>
					<view>
						<view class="uni-flex uni-row uni-mb-5 delay-item uni-mlr-10" v-for="(item,index) in dataList" :key="index"
							@tap="goUploadCredial(item)">
							<view class="uni-flex uni-column left-info">
								<view class="text title">
									{{item.caseId}}<text v-if="item.selfId&&item.selfId.length">({{item.selfId}})</text>
								</view>
								<view class="uni-flex uni-row">
									<view class="date plain-number">{{item.flaightNo}}</view>
									<view class="date">{{item.flaightTime}}</view>
								</view>
							</view>
							<view class="text uni-flex right-status">
								<text class="status" style="background-color:#0c6eb7;border:solid 1px #0c6eb7;" v-if="item.eventType=='less'">少收</text>
								<text class="status" style="background-color:#85B100;border:solid 1px #85B100;" v-if="item.eventType=='more'">多收</text>
								<text class="status" style="background-color:#FF9800;border:solid 1px #FF9800;" v-if="item.eventType=='damage'">破损</text>
							</view>
						</view>
					</view>
				</z-paging>
			</view>

		</view>
		<!-- 底部按钮 -->
		<view class="bottom-btn-fixed">
			<view>
				<button class="btn-f" type="primary" @click="scanQrCode">扫一扫</button>
				<button class="btn-f btn-f-all" type="primary" @click="viewAll">查看全部</button>
			</view>
		</view>
	</view>
</template>

<script>
	// import {
	// 	mapActions
	// } from 'vuex'
	export default {
		data() {
			return {
				createdAt: '',
				url:{
					list:'/event/query'
				},
				dataList:[],
				eventId:'',
				token: ''

			}
		},
		onLoad(e) {
			this.token = uni.getStorageSync('token')
			this.createdAt = this.getDate(Date.now())
			// console.log(this.token);
			console.log(e);
			if(e.eventId){
				this.eventId = e.eventId;
			}
			// let params = {
			// 	createdAt: this.createdAt,
			// 	page: 0,
			// 	limit: 20,
			// eventId:''
			// }
			// this.initData(params);
		},
		onShow() {
			this.queryList(1, 10) 
		},

		methods: {
			// ...mapActions(['loginByLoginCode']),
			queryList(pageNo, pageSize) {
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//这里的请求只是演示，请替换成自己的项目的网络请求，请在网络请求回调中
				//通过this.$refs.paging.complete(请求回来的数组);将请求结果传给z-paging
				let me=this
				var params={page:pageNo,limit:pageSize,token:this.token,createdAt:this.createdAt}
				if(this.eventId.length){
					params.eventId = this.eventId
				}
				this.$http.post(this.url.list,params).then(res=>{
					// console.log(res)
					if(res.data.errcode == 0){
						// me.newsList=res.data.result.records
						this.$refs.paging.complete(res.data.data);
					}else{
						uni.showToast({
							title: res.data.errmsg,
							icon: "none"
						})
					}
				})
			},
			changeDate(e){
				console.log('----change事件:', e);
				this.createdAt = e
				this.queryList(1, 10) 
			},
			goUploadCredial(item) {
				uni.navigateTo({
					url: '/pages/index/uploadImg?data=' + JSON.stringify(item)
				})
			},
			scanQrCode(){
				let me = this;
				uni.scanCode({
					onlyFromCamera: true,
					scanType: 'qrCode',
					hideAlbum: true,
					success: async function(res) {
						// console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						// loginCode:7yu328ewru238hedj238u2390rudi19u32rf923j|eventId:6tgh9876tghj976tghji976tghjio
						if (res.result.includes('|')) {
							// let loginCode = res.result.split('|')[0].split(':')[1]
							let eventId = res.result.split('|')[1].split(':')[1]
							// console.log(loginCode, eventId);
							// let obj = Object.assign({},  {loginCode: loginCode})
							me.eventId = eventId
							uni.reLaunch({
								url: '/pages/index/accidentList?eventId=' +eventId
							})
						
						} else {
							// res.result.split('|')
							let loginCode = res.result.split(':')[1]
							// let obj = Object.assign({},  {loginCode: loginCode})
							uni.reLaunch({
								url: './accidentList'
							})
						}
				
					}
				})
			},
			viewAll(){
				this.eventId = ''
				uni.reLaunch({
					url: './accidentList'
				})
			},
			getDate(date) {
				date = new Date(date)
				const year = date.getFullYear()
				const month = date.getMonth() + 1
				const day = date.getDate()
				return `${year}-${this.addZero(month)}-${this.addZero(day)}`
			},
			addZero(num) {
				if (num < 10) {
					num = `0${num}`
				}
				return num
			},

		}
	}
</script>

<style>
.accident-list .z-paging-content {
	top: 60px !important;
}
/* #ifdef H5 */
	.accident-list  .z-paging-content {
		top: 90px !important;
	}
	/* #endif */
</style>